package com.zh.jwt.controller;

import com.zh.jwt.common.jwt.VerifyToken;
import com.zh.jwt.common.model.ApiResult;
import com.zh.jwt.model.dto.UserDTO;
import com.zh.jwt.model.vo.LoginResultVO;
import com.zh.jwt.model.vo.UserVO;
import com.zh.jwt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 登录
     */
    @PostMapping("/login")
    public ApiResult<LoginResultVO> login(@RequestBody UserDTO dto) {
        return userService.login(dto);
    }

    /**
     * 注册
     */
    @PostMapping("/register")
    public ApiResult<Void> register(@RequestBody UserDTO dto) {
        return userService.register(dto);
    }

    /**
     * 获取用户信息
     */
    @VerifyToken
    @GetMapping("/getUserInfo")
    public ApiResult<UserVO> getUserInfo() {
        return userService.getUserInfo();
    }
}